#include <iostream>
#include <vector>
using namespace std;

int nodeCnt, wayCnt;
vector<vector<int>> map;

int getLongestWay(vector<bool> closeList, int startNode) {
    int maxDistance = 0;
    for (int i = 0; i < nodeCnt; i++) {
        if (map[startNode][i] != -1 && !closeList[i]){
            vector<bool> nextCloseList(closeList);
            int currCost = map[startNode][i];
            nextCloseList[startNode] = true;
            currCost += getLongestWay(nextCloseList, i);
            // 深度优先搜索可能的最长队列
            if (currCost > maxDistance) { maxDistance = currCost; }
        }
    }
    return maxDistance;
}

int main() {
    cin >> nodeCnt >> wayCnt;
    map.resize(nodeCnt, std::vector<int>());
    for (int i = 0; i < nodeCnt; i++) {
        map[i].resize(nodeCnt, -1);
    }
    for (int i = 0; i < wayCnt; i++) {
        int node1, node2, cost;
        cin >> node1 >> node2 >> cost;
        map[node1 - 1][node2 - 1] = cost;
        map[node2 - 1][node1 - 1] = cost;
    }
    // 初始化图
    int result = 0;
    for (int i = 0; i < nodeCnt; i++) {
        vector<bool> closeList; closeList.resize(nodeCnt, false);
        int currDistance = getLongestWay(closeList, i);
        result = currDistance > result ? currDistance : result;
        // 逐个节点搜索
    }
    cout << result;
    return 0;
}